#ifndef _MAP_BUILD_H
#define _MAP_BUILD_H

#include <cstring>
#include "main.h"

typedef enum{
    snake_head_up = 0,snake_head_down,snake_head_left,snake_head_right,/*蛇头图片*/
    snake_body,/*蛇身图片*/
    food,/*食物图片*/
    snake_tail_up,snake_tail_down,snake_tail_left,snake_tail_right,/*蛇尾图片*/
    snake_tail_second_up,snake_tail_second_down,snake_tail_second_left,snake_tail_second_right,
    mapColorOne,mapColorTwo,mapColorThree,mapColorFour/*地图图片*/
}PicCode;


typedef enum
{
    HEAD_TYPE,
    BODY_TYPE,
    TAIL_TYPE,
    SECOND_TAIL_TYPE
}PicType;

class ClientMap
{
public:
    ClientMap()
    {
        bzero(m_map, sizeof(m_map));
    }

/*void set_part_region(const int s_x,const int s_y)*/

//private:
    PicCode m_map[40][40];
};


class Map
{
public:
    Map()
    {
        for (int i = 0; i <80*80; i++)
        {
            if((i*3)%13==1){
                m_map[i/80][i%80] = mapColorTwo;
            }
            else if((i*2)%3==1){
                m_map[i/80][i%80] =  mapColorOne;
            }
            else if(i%37==2 || i%5==6){
                m_map[i/80][i%80] = mapColorFour;
            }
            else{
                m_map[i/80][i%80] =  mapColorThree;
            }
        }
    }
    Map(const Map& other)
    {
        memcpy(this->m_map, other.m_map, sizeof(m_map));
    }

    ~Map()
    {
    }
    void draw_snake_part(PicType type,int x, int y, SnakeDir dir);
    void draw_snake();
    void draw_food();


    void set_map_color(int x, int y, PicCode code)
    {
        m_map[y][x] = code;
    }
    void renew_to_mapcolor(int x, int y)
    {
        //m_map[x][y] = mapColorOne;
        m_map[y][x] = mapColorTwo;
    }
    void set_client_map_region(ClientMap &cmap, int s_x, int s_y)
    {
        //memcpy(/*目的地不太好弄*/);
        for(int i=0; i<40; i++)
        {
            memcpy(cmap.m_map[i], &(this->m_map[i+s_y][s_x]), sizeof(cmap.m_map[i]));
        }
    }

private:
    PicCode m_map[80][80];
    
};

#endif